home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT32.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  4.0 KB  |  113 lines

  1. /*
  2. ==============================================================================
  3.               WordUp Graphics Toolkit Version 5.0                     
  4.                  Demonstration Program 32                         
  5.                                           
  6.  Demonstrates the use of wwarp - press q to end program execution.           
  7.                                           
  8.  *** PROJECT ***                                                             
  9.  This program requires the file WGT5_WC.LIB to be linked.                    
  10.                                           
  11.  *** DATA FILES ***                                                          
  12.  You must have the WGT1.PCX file in your executable dir.       
  13.                                WATCOM C++ VERSION 
  14. ==============================================================================
  15. */
  16.  
  17. #include <wgt5.h>
  18. #include <conio.h>
  19.  
  20.  
  21. void main(void)
  22. {
  23.   short i, t, c, b;
  24.   color pal[256];
  25.   block wgt1;
  26.   short top[320];
  27.   short bot[320];
  28.   short oldmode;                        /* Store previous video mode */
  29.  
  30.   if ( !vgadetected () )
  31.   {
  32.     printf("Error - VGA card required for any WGT program.\n");
  33.     exit (0);
  34.   }
  35.  
  36.   printf ("WGT Example #32\n\n");
  37.   printf ("A full-screen bitmap is warped into various shapes using WWARP.\n");
  38.   printf ("Press a key to warp the object into a new shape. Press Q to end.\n");
  39.   printf ("\n\nPress any key to continue.\n");
  40.   getch ();
  41.  
  42.   oldmode = wgetmode ();         /* Gets the current mode */
  43.   vga256 ();                     /* Initialize graphics mode */
  44.  
  45.   wgt1 = wloadpcx ("wgt1.pcx", pal);   /* Load our image to play with */
  46.   wsetpalette (0, 255, pal);           /* Set the palette */
  47.  
  48.   wcls (0);                            /* Clear screen with black */
  49.   wclip (0, 0, 319, 199);              /* Use full screen */
  50.  
  51.   /* Note: wsline merely stores y coordinates of line in array. You may use
  52.        several calls with various x ranges to make curved lines */
  53.  
  54.   wsline (0, 199, 319, 0, top);               /* Set array top for diagonal line */
  55.   wsline (0, 199, 319, 199, bot);             /* Array bot is horizontal line */
  56.   wwarp (0, 319, top, bot, wgt1, NORMAL);     /* Warp image between lines */
  57.   getch ();                                   /* Wait for key */
  58.   /* squish it */
  59.  
  60.   wcls (0);                                   /* Clear screen */
  61.   wsline (0, 0, 319, 199, top);               /* Set array top for diagonal line */
  62.   wsline (0, 199, 319, 0, bot);               /* Array bot is horizontal line */
  63.   wwarp (0, 319, top, bot, wgt1, NORMAL);     /* Warp image between lines */
  64.   getch ();                                   /* Wait for key */
  65.   /* squish it */
  66.  
  67.   wcls (0);                                   /* Clear screen */
  68.   wsline (0, 100, 100, 0, top);               /* Now create arrow shape */
  69.   wsline (101, 70, 218, 70, top);
  70.   wsline (219, 0, 319, 100, top);
  71.  
  72.   wsline (0, 100, 100, 199, bot);
  73.   wsline (101, 130, 218, 130, bot);
  74.   wsline (219, 199, 319, 100, bot);
  75.   wwarp (0, 319, top, bot, wgt1, NORMAL);     /* Warp image using arrays */
  76.   getch ();                                   /* Wait for keypress */
  77.   /* make a double arrow */
  78.  
  79.   wcls (0);                              /* Clear screen with black */
  80.   do
  81.   {
  82.     b = rand () % 100;
  83.     c = (rand () % 100) + 100;
  84.     for (t = 0; t <= 319; t++)
  85.     {
  86.       i = rand () % 2;
  87.       if (i == 0) 
  88.     b++; 
  89.       else b--;
  90.       i = rand () % 2;
  91.       if (i == 0) 
  92.     c++; 
  93.       else c--;
  94.       if (b > 100) 
  95.     b = 100;
  96.       if (b < 0) 
  97.     b = 0;
  98.       if (c > 197) 
  99.     c = 197;
  100.       if (c < 100) 
  101.     c = 100;
  102.  
  103.       top[t] = b;                         /* Create random wavy lines */
  104.       bot[t] = c;
  105.     }
  106.     wwarp (0, rand () % 320, top, bot, wgt1, XRAY); /* And warp image between them */
  107.     i = getch ();                                   /* Wait for keypress */
  108.   } while (i != 'q');                               /* End program if Q pressed */
  109.  
  110.   wfreeblock (wgt1);                     /* Free memory from image */
  111.   wsetmode (oldmode);                    /* Restore initial video mode */
  112. }
  113.